<?php 
class DomArBasicPropertiesTestCase extends DomArTestUnitTestCase {
	
	public function testText() {
	
		DomArBasicPropertiesTestClass::getTable()->update();
	
		$value = new DomArBasicPropertiesTestClass();
		$value->save();

		$this->assertDatabaseNull( $value->getDbTable(), 'text', $value->id );
		
		$value->text = '';
		$value->save();
		$this->assertDatabaseValue( $value->getDbTable(), 'text', $value->id, '' );
		
		$value->text = NULL;
		$value->save();
		$this->assertDatabaseNull( $value->getDbTable(), 'text', $value->id );
		
		$value->text = 'aa';
		
		$value->save();
		$this->assertDatabaseValue( $value->getDbTable(), 'text', $value->id, 'aa' );
		
		
	}
	
	public function testTextValidate() {
		$value = new DomArBasicPropertiesTestClass();
		$prop = $value->getProperty('text');
		
		$v = '';
		$this->assertEqual( $prop->validate($value,$v), 0);
		
		$v = 'aa';
		$this->assertEqual( $prop->validate($value,$v), 0);
		
		$v = "aa";
		$this->assertEqual( $prop->validate($value,$v), 0);
		
		$v = NULL;
		$this->assertEqual( $prop->validate($value,$v), 0);
		
		$v = 3;
		$this->assertEqual( $prop->validate($value,$v), 1);
		
		$v = array();
		$this->assertEqual( $prop->validate($value,$v), 1);
		
		
		$prop = $value->getProperty('textNotNull');
		$this->assertEqual( $prop->textNotNull, '' );
		$this->assertEqual( $prop->validate($value,$v=NULL), 3);
		$this->assertEqual( $prop->validate($value,$v=''), 0);
		$this->assertEqual( $prop->validate($value,$v=5), 1);
		$this->assertEqual( $prop->validate($value,$v='asd'), 0);
		
		
		$prop = $value->getProperty('textNotEmpty');
		$this->assertEqual( $prop->textNotEmpty, '' );
		$this->assertEqual( $prop->validate($value,$v=NULL), 3);
		$this->assertEqual( $prop->validate($value,$v=''), 3);
		$this->assertEqual( $prop->validate($value,$v=5), 1);
		$this->assertEqual( $prop->validate($value,$v='asd'), 0);
		
	}
	
	
	public function testChar() {
	
		DomArBasicPropertiesTestClass::getTable()->update();
	
		$value = new DomArBasicPropertiesTestClass();
		$value->save();
		
		$this->assertDatabaseNull( $value->getDbTable(), 'char', $value->id );
		
		$value->char = '';
		$value->save();
		$this->assertDatabaseValue( $value->getDbTable(), 'char', $value->id, '' );
		
		$value->char = NULL;
		$value->save();
		$this->assertDatabaseNull( $value->getDbTable(), 'char', $value->id );
		
		$value->char = 'aa';
		$value->charu = 'aaa';
		$value->save();
		$this->assertDatabaseValue( $value->getDbTable(), 'char', $value->id, 'aa' );
		$this->assertDatabaseValue( $value->getDbTable(), 'charu', $value->id, 'aaa' );
		
		DomAr::flushStoredObjects();
		$item = DomArBasicPropertiesTestClass::load( $value->id );
		$this->assertEqual( $item->charu, 'aaa' );
		
		
	}
	
	public function testCharValidate() {
	
		DomArBasicPropertiesTestClass::getTable()->update();
		
		$value = new DomArBasicPropertiesTestClass();
		$prop = $value->getProperty('char');
		
		$v = '';
		$this->assertEqual( $prop->validate($value,$v), 0);
		
		$v = 'aa';
		$this->assertEqual( $prop->validate($value,$v), 0);
		
		$v = "aa";
		$this->assertEqual( $prop->validate($value,$v), 0);
		
		$v = NULL;
		$this->assertEqual( $prop->validate($value,$v), 0);
		
		
		$v = "aaaa";
		$this->assertEqual( $prop->validate($value,$v), 0);
		
		$v = "aaaaa";
		$this->assertEqual( $prop->validate($value,$v), 1);
		
		$v = 3;
		$this->assertEqual( $prop->validate($value,$v), 1);
		
		$v = array();
		$this->assertEqual( $prop->validate($value,$v), 1);
		
		
		// test unique index
		
		$prop = $value->getProperty('charu');
		
		$a = new DomArBasicPropertiesTestClass();
		$a->charu = 'aaaa';
		$a->save();
		
		$v = 'aaaa';
		$this->assertEqual( $prop->validate($a,$v), 2);
		
		$b = new DomArBasicPropertiesTestClass();
		$b->charu = 'aaaa';
		$info = $b->getLastValidationInfo();
		$this->assertEqual( $info['property'], 'charu', 'Unique index is not working!' );
		
		
		$prop = $value->getProperty('charNotNull');
		$this->assertEqual( $prop->charNotNull, '' );
		$this->assertEqual( $prop->validate($value,$v=NULL), 3);
		$this->assertEqual( $prop->validate($value,$v=''), 0);
		$this->assertEqual( $prop->validate($value,$v=5), 1);
		$this->assertEqual( $prop->validate($value,$v='asd'), 0);
		
		$prop = $value->getProperty('charNotEmpty');
		$this->assertEqual( $prop->charNotEmpty, '' );
		$this->assertEqual( $prop->validate($value,$v=NULL), 3);
		$this->assertEqual( $prop->validate($value,$v=''), 3);
		$this->assertEqual( $prop->validate($value,$v=5), 1);
		$this->assertEqual( $prop->validate($value,$v='asd'), 0);
		
	}
	
	
	public function testInt() {
	
		DomArBasicPropertiesTestClass::getTable()->update();
	
		$value = new DomArBasicPropertiesTestClass();
		$value->save();
		
		$this->assertDatabaseNull( $value->getDbTable(), 'int', $value->id );
		
		$value->int = NULL;
		$value->save();
		$this->assertDatabaseNull( $value->getDbTable(), 'int', $value->id );
		
		$value->int = 99;
		$value->intu = 98;
		$value->save();
		$this->assertDatabaseValue( $value->getDbTable(), 'int', $value->id, 99 );
		$this->assertDatabaseValue( $value->getDbTable(), 'intu', $value->id, 98 );
		
		DomAr::flushStoredObjects();
		
		$item = DomArBasicPropertiesTestClass::load( $value->id );
		$this->assertEqual( $item->intu, 98 );
		
	}
	
	public function testIntValidate() {
	
		DomArBasicPropertiesTestClass::getTable()->update();
		
		$value = new DomArBasicPropertiesTestClass();
		$prop = $value->getProperty('int');
		
		$v = -99;
		$this->assertEqual( $prop->validate($value,$v), 0);
		
		$v = 0;
		$this->assertEqual( $prop->validate($value,$v), 0);
		
		$v = 99;
		$this->assertEqual( $prop->validate($value,$v), 0);
		
		$v = NULL;
		$this->assertEqual( $prop->validate($value,$v), 0);
		
		$v = 100;
		$this->assertEqual( $prop->validate($value,$v), 1);
		
		$v = -100;
		$this->assertEqual( $prop->validate($value,$v), 1);
		
		
		// test unique index
		
		$prop = $value->getProperty('intu');
		
		$a = new DomArBasicPropertiesTestClass();
		$a->intu = 5;
		$a->save();
		
		$v = 5;
		$this->assertEqual( $prop->validate($a,$v), 2);
		
		$b = new DomArBasicPropertiesTestClass();
		$b->intu = 5;
		$info = $b->getLastValidationInfo();
		$this->assertEqual( $info['property'], 'intu', 'Unique index is not working!' );
		
		
		$prop = $value->getProperty('intNotNull');
		$this->assertEqual( $prop->intNotNull, '' );
		$this->assertEqual( $prop->validate($value,$v=NULL), 3);
		$this->assertEqual( $prop->validate($value,$v='5'), 1);
		$this->assertEqual( $prop->validate($value,$v=0), 0);
		
	}
	
	
	public function testFloat() {
	
		DomArBasicPropertiesTestClass::getTable()->update();
	
		$value = new DomArBasicPropertiesTestClass();
		$value->save();
		
		$this->assertDatabaseNull( $value->getDbTable(), 'float', $value->id );
		
		$value->float = NULL;
		$value->save();
		$this->assertDatabaseNull( $value->getDbTable(), 'float', $value->id );
		
		$value->float = 999.99;
		$value->floatu = 888.88;
		$value->save();
		$this->assertDatabaseValue( $value->getDbTable(), 'float', $value->id, 999.99 );
		$this->assertDatabaseValue( $value->getDbTable(), 'floatu', $value->id, 888.88 );
		
		DomAr::flushStoredObjects();
		
		$item = DomArBasicPropertiesTestClass::load( $value->id );
		$this->assertEqual( $item->floatu, 888.88 );
		
		$c = new DomArBasicPropertiesTestClass();
		$c->floatu = 888.88;
		
	}
	
	public function testFloatValidate() {
	
		DomArBasicPropertiesTestClass::getTable()->update();
		
		$value = new DomArBasicPropertiesTestClass();
		$prop = $value->getProperty('float');
		
		$v = -999;
		$this->assertEqual( $prop->validate($value,$v), 0);
		
		$v = -999.99;
		$this->assertEqual( $prop->validate($value,$v), 0);
		
		$v = 0.01;
		$this->assertEqual( $prop->validate($value,$v), 0);
		
		$v = 0;
		$this->assertEqual( $prop->validate($value,$v), 0);
		
		$v = 999.99;
		$this->assertEqual( $prop->validate($value,$v), 0);
		
		$v = 999;
		$this->assertEqual( $prop->validate($value,$v), 0);
		
		$v = NULL;
		$this->assertEqual( $prop->validate($value,$v), 0);
		
		
		$v = 1000.01;
		$this->assertEqual( $prop->validate($value,$v), 1);
		
		$v = -1000.01;
		$this->assertEqual( $prop->validate($value,$v), 1);
		
		$v = 1000;
		$this->assertEqual( $prop->validate($value,$v), 1);
		
		$v = -1000;
		$this->assertEqual( $prop->validate($value,$v), 1);
		
		
		
		// test unique index
		
		$prop = $value->getProperty('floatu');
		
		$a = new DomArBasicPropertiesTestClass();
		$a->floatu = 5;
		$a->save();
		
		$v = 5;
		$this->assertEqual( $prop->validate($a,$v), 2);
		
		$b = new DomArBasicPropertiesTestClass();
		$b->floatu = 5;
		$info = $b->getLastValidationInfo();
		$this->assertEqual( $info['property'], 'floatu', 'Unique index is not working!' );
		
		
		$prop = $value->getProperty('floatNotNull');
		$this->assertEqual( $prop->floatNotNull, '' );
		$this->assertEqual( $prop->validate($value,$v=NULL), 3);
		$this->assertEqual( $prop->validate($value,$v='5.5'), 1);
		$this->assertEqual( $prop->validate($value,$v=0.0), 0);
		
	}
	
	
	public function testBool() {
	
		DomArBasicPropertiesTestClass::getTable()->update();
	
		$value = new DomArBasicPropertiesTestClass();
		$value->save();

		$value->bool = true;
		$value->save();
		$this->assertDatabaseValue( $value->getDbTable(), 'bool', $value->id, 1 );
		
		$value->bool = false;
		$value->save();
		$this->assertDatabaseValue( $value->getDbTable(), 'bool', $value->id, 0 );
		
		
	}
	
	public function testBoolValidate() {
		$value = new DomArBasicPropertiesTestClass();
		$prop = $value->getProperty('bool');
		
		$v = true;
		$this->assertEqual( $prop->validate($value,$v), 0);
		
		$v = false;
		$this->assertEqual( $prop->validate($value,$v), 0);
		
		$v = "aa";
		$this->assertEqual( $prop->validate($value,$v), 1);
		
		$v = NULL;
		$this->assertEqual( $prop->validate($value,$v), 0);
		
		$v = 0;
		$this->assertEqual( $prop->validate($value,$v), 1);
		
		$v = 1;
		$this->assertEqual( $prop->validate($value,$v), 1);
		
		$v = 2;
		$this->assertEqual( $prop->validate($value,$v), 1);
		
		$v = array();
		$this->assertEqual( $prop->validate($value,$v), 1);
		
		$prop = $value->getProperty('boolNotNull');
		$this->assertEqual( $prop->boolNotNull, NULL );
		$this->assertEqual( $prop->validate($value,$v=NULL), 3);
		$this->assertEqual( $prop->validate($value,$v='1'), 1);
		$this->assertEqual( $prop->validate($value,$v=false), 0);
		
	}
	
	
	public function testArray() {
	
		DomArBasicPropertiesTestClass::getTable()->update();
	
		$value = new DomArBasicPropertiesTestClass();
		$value->save();

		$value->array = array();
		$value->save();
		$this->assertDatabaseValue( $value->getDbTable(), 'array', $value->id, 'a:0:{}' );
		
	}
		
	public function testArrayValidate() {
		$value = new DomArBasicPropertiesTestClass();
		$prop = $value->getProperty('array');
		
		$v = array();
		$this->assertEqual( $prop->validate($value,$v), 0);
		
		$v = array('a'=>'b');
		$this->assertEqual( $prop->validate($value,$v), 0);
		
		$v = "aa";
		$this->assertEqual( $prop->validate($value,$v), 1);
		
		$v = NULL;
		$this->assertEqual( $prop->validate($value,$v), 0);
		
		$v = 0;
		$this->assertEqual( $prop->validate($value,$v), 1);
		
	}

	
	public function testEmail() {
	
		DomArBasicPropertiesTestClass::getTable()->update();
	
		$value = new DomArBasicPropertiesTestClass();
		$value->save();
		
		$this->assertDatabaseNull( $value->getDbTable(), 'email', $value->id );
		
		$value->email = '';
		$value->save();
		$this->assertDatabaseValue( $value->getDbTable(), 'email', $value->id, '' );
		
		$value->email = NULL;
		$value->save();
		$this->assertDatabaseNull( $value->getDbTable(), 'email', $value->id );
		
		
		$value->email = 'aa@aa.ee';
		$this->assertTrue($value->save());
		$this->assertDatabaseValue( $value->getDbTable(), 'email', $value->id, 'aa@aa.ee' );

		$value->email = 'aa@aa.ee';
		$this->assertTrue( $value->save() );
		$this->assertTrue( $value->validated() );

		// test unique
		$second = new DomArBasicPropertiesTestClass();
		$second->email = 'aa@aa.ee';
		$this->assertFalse( $second->save() );
		$this->assertFalse( $second->validated() );
		
		DomAr::flushStoredObjects();
		$item = DomArBasicPropertiesTestClass::load( $value->id );
		$this->assertEqual( $item->email, 'aa@aa.ee' );
		
		
		// test before save validation

		$value = new DomArBasicPropertiesTestClass();
		$value->forceSet('emailNotNull',NULL);
		$value->setChanged('emailNotNull',false);
		$this->assertFalse( $value->save() );

		$value = new DomArBasicPropertiesTestClass();
		$value->forceSet('emailNotEmpty','');
		$value->setChanged('emailNotNull',false);
		$this->assertFalse( $value->save() );
	}
	
	public function testEmailValidate() {
		
		$item = new DomArBasicPropertiesTestClass('a');
		
		
		$item->email = array('aa@aa.ee','aa@aa.ee');
		$this->assertTrue( $item->validated() );
		$item->setValidated(true);
		
		$item->email = array('aaa@aa.ee','aa@aa.ee');
		$this->assertFalse( $item->validated() );
		$item->setValidated(true);
		
		$item->email = 'apps+375005261878.1269861549.8141d16794265773e344bcb768d12cba@proxymail.facebook.com';
		$this->assertTrue( $item->validated() );
		$item->setValidated(true);
		
		
		// test bad
		
		$item->email = 'a@a';
		$this->assertFalse( $item->validated() );
		$item->setValidated(true);
		
		$item->email = 'a@a.a';
		$this->assertFalse( $item->validated() );
		$item->setValidated(true);
		
		$item->email = 'aa@a.aa';
		$this->assertFalse( $item->validated() );
		$item->setValidated(true);
		
		$item->email = 'a@aa.aa';
		$this->assertFalse( $item->validated() );
		$item->setValidated(true);
		
		$item->email = 'a@aa.aa';
		$this->assertFalse( $item->validated() );
		$item->setValidated(true);
		
		$item->email = 'aa@aa.a';
		$this->assertFalse( $item->validated() );
		$item->setValidated(true);
		
		$item->email = 'a_a@a';
		$this->assertFalse( $item->validated() );
		$item->setValidated(true);
		
		$item->email = 'a.a.@aa.aa';
		$this->assertFalse( $item->validated() );
		$item->setValidated(true);
		

		// test good
		
		$item->email = 'aa@aa.aa';
		$this->assertTrue( $item->validated() );
		$item->setValidated(true);
		
		$item->email = 'aa.aa@aa.aa';
		$this->assertTrue( $item->validated() );
		$item->setValidated(true);
		
		$item->email = 'aa_aa@aa.aa';
		$this->assertTrue( $item->validated() );
		$item->setValidated(true);
		
		$item->email = 'a_a.a_a@aa.aa';
		$this->assertTrue( $item->validated() );
		$item->setValidated(true);
		
		$item->email = 'a-a.a.a@aa.aa';
		$this->assertTrue( $item->validated() );
		$item->setValidated(true);
		
		$item->email = 'aa_@aa.aa';
		$this->assertTrue( $item->validated() );
		$item->setValidated(true);
		
		$item->email = '_a_a_@aa.aa';
		$this->assertTrue( $item->validated() );
		$item->setValidated(true);
		
		$item->email = '-a-a-@aa.aa';
		$this->assertTrue( $item->validated() );
		$item->setValidated(true);
		
		// test not null
		$item->emailNotNull = 'aa@aa.ee';
		
		$item->emailNotNull = '';
		$this->assertTrue( $item->validated() );
		$item->setValidated(true);
		
		$item->emailNotNull = NULL;
		$this->assertFalse( $item->validated() );
		$item->setValidated(true);
		
		$item->emailNotNull = 'aa@aa.aa';
		$this->assertTrue( $item->validated() );
		$item->setValidated(true);
		
		
		// test not empty
		$item->emailNotEmpty = 'aa@aa.ee';
		
		$item->emailNotEmpty = '';
		$this->assertFalse( $item->validated() );
		$item->setValidated(true);
		
		$item->emailNotEmpty = NULL;
		$this->assertFalse( $item->validated() );
		$item->setValidated(true);
		
		$item->emailNotEmpty = 'aa@aa.aa';
		$this->assertTrue( $item->validated() );
		$item->setValidated(true);
	}
	
	
	public function testPassword() {
		
		DomArBasicPropertiesTestClass::getTable()->update();
		
		$item = new DomArBasicPropertiesTestClass('a');
		$item->password = 'myPass22';
		$this->assertEqual( $item->password, md5('myPass22') );
		
		$item->password = '';
		$this->assertEqual( $item->password, md5('myPass22') );
		$item->setValidated(true);
		
		$item->password = array('myPass99','myPass99');
		$this->assertTrue( $item->validated() );
		$item->setValidated(true);
		
		$item->password = array('myPass99','myPass998');
		$this->assertFalse( $item->validated() );
		$item->setValidated(true);
		
		$this->assertTrue($item->save());
	
		$this->assertDatabaseValue( $item->getDbTable(), 'password', $item->id, md5('myPass99') );
		
		// test old password
		$item->setValidated(true);
		$item->password = 'myPass22';
		$item->password = array('myPass99','myPass99','wrongPass');
		$this->assertIdentical( $item->getProperty('password')->validate($item,$pass=array('myPass99','myPass99','wrongPass')), 7 );
		$this->assertFalse( $item->validated() );
		$item->setValidated(true);
		
		$item->password = 'myPass22';
		$item->password = array('myPass99','myPass99','myPass22');
		$this->assertTrue( $item->validated() );
		$item->setValidated(true);
		
		
		// test before save validation

		$value = new DomArBasicPropertiesTestClass();
		$value->forceSet('passwordNotNull',NULL);
		$value->setChanged('passwordNotNull',false);
		$this->assertFalse( $value->save() );

		$value = new DomArBasicPropertiesTestClass();
		$value->forceSet('passwordNotEmpty','');
		$value->setChanged('passwordNotNull',false);
		$this->assertFalse( $value->save() );
		
	}
	
	public function testPasswordValidate() {
		
		$item = new DomArBasicPropertiesTestClass('a');
		
		$property = new DomArProperty_Password('password',false,false,6,3);
		$this->assertIdentical( $property->validate($item,$pass='aaAA'), 5 );
		
		$property = new DomArProperty_Password('password',false,false,6,3);
		$this->assertIdentical( $property->validate($item,$pass='aaAA01'), 0 );
		$this->assertIdentical( $property->validate($item,$pass='aaaAAA'), 6 );
		$this->assertIdentical( $property->validate($item,$pass='aaa000'), 6 );
		$this->assertIdentical( $property->validate($item,$pass='012AAA'), 6 );
		
		$property = new DomArProperty_Password('password',false,false,6,2);
		$this->assertIdentical( $property->validate($item,$pass='aaAA00'), 0 );
		$this->assertIdentical( $property->validate($item,$pass='aaaAAA' ), 0 );
		$this->assertIdentical( $property->validate($item,$pass='AAA000' ), 0 );
		$this->assertIdentical( $property->validate($item,$pass='aaa000' ), 0 );
		$this->assertIdentical( $property->validate($item,$pass='aaaaaa' ), 6 );
		
		$property = new DomArProperty_Password('password',false,false,6,1);
		$this->assertIdentical( $property->validate($item,$pass='aaaaaa' ), 0 );
		$this->assertIdentical( $property->validate($item,$pass='AAAAAA' ), 0 );
		$this->assertIdentical( $property->validate($item,$pass='000000' ), 0 );
		$this->assertIdentical( $property->validate($item,$pass='......' ), 6 );
		
		
		// test not null

		$item = new DomArBasicPropertiesTestClass('a');
		$item->passwordNotNull = '';
		$this->assertTrue( $item->validated() );
		$item->setValidated(true);
		

		$item = new DomArBasicPropertiesTestClass('a');
		$item->passwordNotNull = NULL;
		$this->assertFalse( $item->validated() );
		$item->setValidated(true);

		$item = new DomArBasicPropertiesTestClass('a');
		$item->passwordNotNull = 'asdf9034KD';
		$this->assertTrue( $item->validated() );
		$item->setValidated(true);
		
		
		// test not empty
		$item = new DomArBasicPropertiesTestClass('a');
		$item->passwordNotEmpty = '';
		$this->assertFalse( $item->validated() );
		$item->setValidated(true);
		
		$item = new DomArBasicPropertiesTestClass('a');
		$item->passwordNotEmpty = NULL;
		$this->assertFalse( $item->validated() );
		$item->setValidated(true);
		
		$item = new DomArBasicPropertiesTestClass('a');
		$item->passwordNotEmpty = 'asdf9034KD';
		$this->assertTrue( $item->validated() );
		$item->setValidated(true);
	}

	
	public function testNumber() {
		DomArNumberTestClass::getTable()->update();
		
		$item = new DomArNumberTestClass();
		$item->save();
		$this->assertDatabaseNull( $item->getDbTable(), 'number52', $item->id );
		
		$item->number52 = 999.99;
		$item->save();
		$this->assertDatabaseValue( $item->getDbTable(), 'number52', $item->id, 999.99 );
		
		$item->number52 = NULL;
		$item->save();
		$this->assertDatabaseNull( $item->getDbTable(), 'number52', $item->id );
		
		$item->number52 = 999.99;
		$item->save();
		$this->assertDatabaseValue( $item->getDbTable(), 'number52', $item->id, 999.99 );
		
		$item->number63u = 111.111;
		$item->save();
		$this->assertDatabaseValue( $item->getDbTable(), 'number52', $item->id, 999.99 );
		
		$bigNumber = (float)99999999999999;
		$item->numberBig = $bigNumber;
		$item->save();
		$this->assertDatabaseValue( $item->getDbTable(), 'numberBig', $item->id, $bigNumber );
		
		
		DomAr::flushStoredObjects();
		
		$item = DomArNumberTestClass::load( $item->id );
		$this->assertIdentical( $item->number52, 999.99 );
		$this->assertIdentical( $item->number63u, 111.111 );

		// test validators
		$prop = $item->getProperty('number52');
		$this->assertIdentical( $prop->validate( $item, $v=100.0 ), 0);
		$this->assertIdentical( $prop->validate( $item, $v=0.0 ), 0);
		$this->assertIdentical( $prop->validate( $item, $v=-999.99 ), 0);
		$this->assertIdentical( $prop->validate( $item, $v=NULL ), 0);
		$this->assertIdentical( $prop->validate( $item, $v=-9999.99 ), 1);
		$this->assertIdentical( $prop->validate( $item, $v=9999.99 ), 1);
		$this->assertIdentical( $prop->validate( $item, $v=-999.999 ), 1);
		$this->assertIdentical( $prop->validate( $item, $v=999.999 ), 1);
		
		$prop = $item->getProperty('number63u');
		$this->assertIdentical( $prop->validate( $item, $v=111.112 ), 0);
		$this->assertIdentical( $prop->validate( $item, $v=111.111 ), 2);
		
		$prop = $item->getProperty('number3notNull');
		$this->assertIdentical( $prop->validate( $item, $v=999 ), 0);
		$this->assertIdentical( $prop->validate( $item, $v=NULL ), 3);
		
		$prop = $item->getProperty('number3In');
		$this->assertIdentical( $prop->validate( $item, $v=NULL ), 0);
		$this->assertIdentical( $prop->validate( $item, $v=0 ), 4);
		$this->assertIdentical( $prop->validate( $item, $v=1 ), 0);
		$this->assertIdentical( $prop->validate( $item, $v=2 ), 0);
		$this->assertIdentical( $prop->validate( $item, $v=3 ), 4);
		$this->assertIdentical( $prop->validate( $item, $v=4 ), 0);
		$this->assertIdentical( $prop->validate( $item, $v=5 ), 0);
		$this->assertIdentical( $prop->validate( $item, $v=6 ), 0);
		$this->assertIdentical( $prop->validate( $item, $v=7 ), 4);
		
		$prop = $item->getProperty('number63In');
		$this->assertIdentical( $prop->validate( $item, $v=NULL ), 0);
		$this->assertIdentical( $prop->validate( $item, $v=0.0 ), 4);
		$this->assertIdentical( $prop->validate( $item, $v=1.5 ), 0);
		$this->assertIdentical( $prop->validate( $item, $v=2.5 ), 0);
		$this->assertIdentical( $prop->validate( $item, $v=2.501 ), 4);
		$this->assertIdentical( $prop->validate( $item, $v=4.199 ), 4);
		$this->assertIdentical( $prop->validate( $item, $v=4.2 ), 0);
		$this->assertIdentical( $prop->validate( $item, $v=5.1 ), 0);
		$this->assertIdentical( $prop->validate( $item, $v=6.8 ), 0);
		$this->assertIdentical( $prop->validate( $item, $v=6.801 ), 4);
		
	}
	
	
	public function testFullText() {
		DomArFulltextTestClass::getTable()->update();
		
		$table = DomArFulltextTestClass::getTable();
		$indexes = $table->getIndexes();
		
		$this->assertEqual( $indexes[1]['name'], 'introduction');
		$this->assertEqual( $indexes[1]['type'], 'fulltext');
		
		$this->assertEqual( $indexes[2]['name'], 'key');
		$this->assertEqual( $indexes[2]['type'], 'fulltext');
		
		$this->assertEqual( $indexes[3]['name'], 'ci_title_contents');
		$this->assertEqual( $indexes[3]['type'], 'fulltext');
		
		$this->assertEqual( $indexes[4]['name'], 'ci_title_contents');
		$this->assertEqual( $indexes[4]['type'], 'fulltext');
		
		$a = new DomArFulltextTestClass();
		$a->introduction = 'What did you do yesterday? I was coding!';
		$a->save();
		
		$b = new DomArFulltextTestClass();
		$b->introduction = 'I am cooking meat tonight';
		$b->save();
		
		$c = new DomArFulltextTestClass();
		$c->introduction = 'Who the hell wrote this code? Yesterday it was ok!';
		$c->save();
		
		$d = new DomArFulltextTestClass();
		$d->introduction = 'Writing code is easy!';
		$d->save();
		
		$e = new DomArFulltextTestClass();
		$e->introduction = 'Yesterday i was doing nothing!';
		$e->save();
		
		$items = DomArFulltextTestClass::query()->matchAgainst('introduction','code')->commit()->toArray();
		$this->assertEqual( $d, $items[0]);
		$this->assertEqual( $c, $items[1]);
		
		$items = DomArFulltextTestClass::query()->matchAgainst('introduction','code')->orderBy('t.id')->commit()->toArray();
		$this->assertEqual( $c, $items[0]);
		$this->assertEqual( $d, $items[1]);
		
		$items = DomArFulltextTestClass::query()->matchAgainst('introduction','yesterday')->commit()->toArray();
		$this->assertEqual( $items, array() );		
	}
	
	
	public function testEnum() {
	
		DomArBasicPropertiesTestClass::getTable()->update();

		$value = new DomArBasicPropertiesTestClass();
		$value->save();
		
		$this->assertDatabaseNull( $value->getDbTable(), 'enum', $value->id );
		
		$value->enum = NULL;
		$value->save();
		$this->assertDatabaseNull( $value->getDbTable(), 'enum', $value->id );
		
		$value->enum = 'a';
		$value->save();
		$this->assertDatabaseValue( $value->getDbTable(), 'enum', $value->id, 'a' );
		
		$value->enum = 1;
		$value->save();
		$this->assertDatabaseValue( $value->getDbTable(), 'enum', $value->id, 'b' );
		
		$value->enum = NULL;
		$value->save();
		$this->assertDatabaseNull( $value->getDbTable(), 'enum', $value->id );
		
		$value->delete();
		
		$value = new DomArBasicPropertiesTestClass();
		$value->enum = 'c';
		$value->save();
		$this->assertDatabaseValue( $value->getDbTable(), 'enum', $value->id, 'c' );
	}
	
	public function testEnumValidate() {
		$value = new DomArBasicPropertiesTestClass();
		$prop = $value->getProperty('enum');
		
		$v = 'a';
		$this->assertEqual( $prop->validate($value,$v), 0);
		
		$v = 'b';
		$this->assertEqual( $prop->validate($value,$v), 0);
		
		$v = "c";
		$this->assertEqual( $prop->validate($value,$v), 0);
		
		$v = 0;
		$this->assertEqual( $prop->validate($value,$v), 0);
		
		$v = 1;
		$this->assertEqual( $prop->validate($value,$v), 0);
		
		$v = 2;
		$this->assertEqual( $prop->validate($value,$v), 0);
		
		$v = NULL;
		$this->assertEqual( $prop->validate($value,$v), 0);
		
		$v = 'aa';
		$this->assertEqual( $prop->validate($value,$v), 1);
		
		$v = 3;
		$this->assertEqual( $prop->validate($value,$v), 1);
	}
	
	
	public function testSet() {
	
		DomArBasicPropertiesTestClass::getTable()->update();

		$value = new DomArBasicPropertiesTestClass();
		$value->save();
		
		$this->assertDatabaseNull( $value->getDbTable(), 'set', $value->id );
		
		$value->set = NULL;
		$value->save();
		$this->assertDatabaseNull( $value->getDbTable(), 'set', $value->id );
		
		$value->set = array('a');
		$value->save();
		$this->assertDatabaseValue( $value->getDbTable(), 'set', $value->id, 'a' );
		
		$value->set = array(1);
		$value->save();
		$this->assertDatabaseValue( $value->getDbTable(), 'set', $value->id, 'b' );
		
		$value->set = array('a','c');
		$value->save();
		$this->assertDatabaseValue( $value->getDbTable(), 'set', $value->id, 'a,c' );
		
		$value->set = array(1,2);
		$value->save();
		$this->assertDatabaseValue( $value->getDbTable(), 'set', $value->id, 'b,c' );
		
		$value->set = NULL;
		$value->save();
		$this->assertDatabaseNull( $value->getDbTable(), 'set', $value->id );
		
		$value->delete();
		
		$value = new DomArBasicPropertiesTestClass();
		$value->set = array('c');
		$value->save();
		$this->assertDatabaseValue( $value->getDbTable(), 'set', $value->id, 'c' );
		$value->delete();
		
		$value = new DomArBasicPropertiesTestClass();
		$value->set = array('a','b','c');
		$value->save();
		$this->assertDatabaseValue( $value->getDbTable(), 'set', $value->id, 'a,b,c' );
	}
	
	public function testSetValidate() {
		$value = new DomArBasicPropertiesTestClass();
		$prop = $value->getProperty('set');
		
		$v = array('a');
		$this->assertEqual( $prop->validate($value,$v), 0);
		
		$v = array('b');
		$this->assertEqual( $prop->validate($value,$v), 0);
		
		$v = array("c");
		$this->assertEqual( $prop->validate($value,$v), 0);
		
		$v = array(0);
		$this->assertEqual( $prop->validate($value,$v), 0);
		
		$v = array(1);
		$this->assertEqual( $prop->validate($value,$v), 0);
		
		$v = array(2);
		$this->assertEqual( $prop->validate($value,$v), 0);
		
		$v = NULL;
		$this->assertEqual( $prop->validate($value,$v), 0);
		
		$v = array('aa');
		$this->assertEqual( $prop->validate($value,$v), 1);
		
		$v = array(3);
		$this->assertEqual( $prop->validate($value,$v), 1);
	}

	
	public function testArrayAccess() {
		
		$value = new DomArBasicPropertiesTestClass();
		
		$value['text'] = 'Hello';
		$this->assertIdentical( $value['text'], 'Hello');
		$this->assertIdentical( $value->text, 'Hello');
		
		$this->assertIdentical( $value['textNotEmpty'], 'a');
	}

}

?>